package org.dromara.common.tenant.config;

import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import org.dromara.common.mybatis.config.MybatisPlusConfiguration;
import org.dromara.common.tenant.handle.PlusTenantLineHandler;
import org.dromara.common.tenant.properties.TenantProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
 * 租户配置
 * @author Stars
 */
@ConditionalOnBean(MybatisPlusConfiguration.class)
@AutoConfiguration(after = {MybatisPlusConfiguration.class})
@ConditionalOnProperty(value = "tenant.enable", havingValue = "true")
public class MybatisPlusConfig {

    /**
     * 多租户插件
     */
    @Bean
    public TenantLineInnerInterceptor tenantLineInnerInterceptor(TenantProperties tenantProperties) {
        return new TenantLineInnerInterceptor(new PlusTenantLineHandler(tenantProperties));
    }

}
